args Controls CreativityMeasure 


local lab p_CreatOcc

preserve

* setup
replace Creativity=creativityt_`CreativityMeasure'_7


local ipw=1

local  CreatOcc     CreatOcc_I33    CreatOcc_I42  CreatOcc_I46   CreatOcc_I50   CreatOcc_I55

su  `CreatOcc'

* calculate ipw weights
foreach y of local  CreatOcc {
	if `ipw'==1{
		ge io=`y'!=.
		qui logit io $HDC_0
		drop io
		predict p_`y', pr
	}

	if `ipw'==0{
		ge  p_`y'=1
	}

}	

* reshape to long dataset
reshape long CreatOcc_I p_CreatOcc_I SE_I cCSC_1_I cCSC_2_I cCSC_3_I cCSC_4_I cCSC_5_I cCSC_6_I cCSC_7_I, i(NCDSID) j(age)




************ employees **********************************************************

* effect on  CreatOcc
rifhdreg  CreatOcc  `Controls'  [pweight=1/p_CreatOcc] if SE_I==0, rif(mean) cluster(NCDSID)
mat b = e(b)
mat b = b'
svmat b
qui su b1 if b1!=0
mat define p= r(N)
drop b1
qui estadd scalar Par=p[1,1]
qui estadd scalar Ni=e(N_clust) 
estadd scalar mdv=e(rifmean) 
est sto es_CreatOcc1_Emp


* controlling for education
rifhdreg  CreatOcc  `Controls' mQual16 mQual18 mUniQual MissingQual16 MissingQual18 MissingUniQual [pweight=1/p_CreatOcc]  if SE_I==0, rif(mean) cluster(NCDSID)
mat b = e(b)
mat b = b'
svmat b
qui su b1 if b1!=0
mat define p= r(N)
drop b1
qui estadd scalar Par=p[1,1]
qui estadd scalar Ni=e(N_clust) 
estadd scalar mdv=e(rifmean) 
est sto es_CreatOcc2_Emp


************ self-employeed *****************************************************

* effect on  CreatOcc
rifhdreg  CreatOcc  `Controls'  [pweight=1/p_CreatOcc] if SE_I==1, rif(mean) cluster(NCDSID)
mat b = e(b)
mat b = b'
svmat b
qui su b1 if b1!=0
mat define p= r(N)
drop b1
qui estadd scalar Par=p[1,1]
qui estadd scalar Ni=e(N_clust) 
estadd scalar mdv=e(rifmean) 
est sto es_CreatOcc1_SE



* controlling for education
rifhdreg  CreatOcc  `Controls' mQual16 mQual18 mUniQual MissingQual16 MissingQual18 MissingUniQual [pweight=1/p_CreatOcc]  if SE_I==1, rif(mean) cluster(NCDSID)
mat b = e(b)
mat b = b'
svmat b
qui su b1 if b1!=0
mat define p= r(N)
drop b1
qui estadd scalar Par=p[1,1]
qui estadd scalar Ni=e(N_clust) 
estadd scalar mdv=e(rifmean) 
est sto es_CreatOcc2_SE


restore
